package com.test.chatdemo.service.impl;

import com.test.chatdemo.service.ChatHistoryRepository;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ChatHistoryRepositoryImpl implements ChatHistoryRepository {

    private final Map<String, List<String>> chatHistory = new HashMap<>();


    @Override
    public void save(String type, String chatId) {
//        if(!chatHistory.containsKey(type)) {
//            chatHistory.put(type, new ArrayList<>());
//        }
//        List<String> chatIds = chatHistory.get(type);
        List<String> chatIds = chatHistory.computeIfAbsent(type, k -> new ArrayList<>());
        if(chatIds.contains(chatId)) {
            return;
        }
    }

    @Override
    public List<String> getChatIds(String type) {

        List<String> chatIds = chatHistory.get(type);
        return chatIds == null ? new ArrayList<>() : chatIds;
    }

}
